var websocket = null;
if ('WebSocket' in window) {
    websocket = new WebSocket("wss://magnet.jtpark.cn/websocket/socketServer");
}
else if ('MozWebSocket' in window) {
    websocket = new MozWebSocket("wss://magnet.jtpark.cn/websocket/socketServer");
}
else {
    websocket = new SockJS("https://magnet.jtpark.cn/sockjs/socketServer");
}
websocket.onopen = onOpen;
websocket.onmessage = onMessage;
websocket.onerror = onError;
websocket.onclose = onClose;
var index=0;
function onOpen(openEvt) {
    console.log("opening");
    //alert(openEvt.Data);
}

function onMessage(evt) {
    console.log(evt.data);
    var device = JSON.parse(evt.data);
    console.log(deviceId);
    console.log(device.deviceId);
    console.log(deviceId==device.deviceId);
    if(deviceId==device.deviceId){
        var status ="-";
        if(device.status==1){
            status="有车";
        }
        console.log(status);
        var xx="-";
        var time = moment(device.updateTime).format('YYYY-MM-DD HH:mm:ss');
        var sig=device.signalStrength?device.signalStrength:xx;
        var zzzz='<tr data-index="'+index+'">' +
            '<td style="text-align: center; vertical-align: middle; width: 40px; ">' + deviceName+ '</td>' +
            '<td style="text-align: center; vertical-align: middle; width: 20px; ">' + device.sequence+ '</td>' +
            '<td style="text-align: center; vertical-align: middle; width: 20px; ">' + status+ '</td>' +
            '<td style="text-align: center; vertical-align: middle; width: 80px; ">' + sig+ '</td>' +
            '<td style="text-align: center; vertical-align: middle; width: 80px; ">' + time+ '</td>' +
            '</tr>';
        $("#tableBody").append(zzzz);
        index++;
    }

}
function onError() {}
function onClose() {}

function doSend() {
    if (websocket.readyState == websocket.OPEN) {
        var msg = document.getElementById("inputMsg").value;
        websocket.send(msg);//调用后台handleTextMessage方法
        alert("发送成功!");
    } else {
        alert("连接失败!");
    }
}